﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace OnlineShop
{
    /// <summary>
    /// Interaction logic for ShopMenu.xaml
    /// </summary>
    public partial class ShopMenu : Window
    {
        public ShopMenu()
        {
            InitializeComponent();
            try
            {
                // Only get files that begin with the letter "c." 
                string[] dirs = Directory.GetFiles(@"Products\\", "*");
                for (int i = 0; i < dirs.Length; i++)
                {
                    int index = dirs[i].IndexOf('\\');
                    dirs[i] = dirs[i].Remove(0, index + 2);
                    dirs[i] = dirs[i].Remove(dirs[i].Length - 4, 4);
                    StreamReader reader = new StreamReader("Products\\" + dirs[i] + ".txt");
                    string[] text;
                    using (reader)
                    {
                        text = reader.ReadToEnd().Split(new char[] {':'}, StringSplitOptions.RemoveEmptyEntries);
                    }
                    this.textBox.Text += text[1] + "\n----------\n";
                }
            }
            catch (Exception exep)
            {
                MessageBox.Show("The process failed: {0}", exep.ToString());
            }
            return;
        }

        private void OnNewProductClicked(object sender, RoutedEventArgs e)
        {
            AddProductMenu window = new AddProductMenu();
            window.Show();
            this.Close();
        }

        private void OnBackToMainMenuClick(object sender, RoutedEventArgs e)
        {
            StartMenu window = new StartMenu();
            window.Show();
            this.Close();
        }
    }
}
